import csv
from time import time
import pymysql.cursors
from random import choice


def insert_mysql(conf,sql):
    conn = pymysql.connect(**conf)
    print('mysql连接成功')
    cur = conn.cursor()
    cur.execute(sql)
    conn.commit()
    # 关闭游标
    cur.close()

    # 关闭连接
    conn.close()


if __name__ == "__main__":
    # 建立数据库连接，注意中文编码方式utf8
    conf = {
        'host': '192.168.16.18',
        'port': 6006,
        'user': 'dev',
        'password': 'jmdevcd',
        'db': 'growth_unmanned_shelves',
        'charset': 'utf8'
    }

    for i in range(0, 99):
        # sql = "INSERT INTO `growth_unmanned_shelves`.`red_envelope`( `uid`, `from_uid`, `out_trade_id`, `is_big_bonus`, `is_risk`, `amount`, `activity_id`, `status`, `create_time`, `receive_time`, `type`)" \
        #       " VALUES ( %s, %s, %s, 0, 0, 0, 26, 0, %s, 0, 'car_fee');" % (
        #              34002, 200000001 + i, '999002', '1528964067')  # 司机uid、用户id、交易订单编号、创建时间、

        sql = '''INSERT  INTO  `growth_unmanned_shelves`. `meidian_order`(`uid`, `order_sn`, `order_id`, `shop_id`, `business_id`, `driver_id`,
                        `driver_relation_login_id`, `trade_id`, `quantity`, `status`, `payment_status`, `type`,
                        `amount`,
                        `create_time`, `payment_time`, `payment_method`, `cancel_time`, `refund_submit_time`,
                        `refund_complete_time`, `expire_time`, `online_paid_amount`, `balance_paid_amount`,
                        `discount_amount`, `promo_card`, `promo_card_discount_amount`, `red_envelope`,
                        `red_envelope_discount_amount`, `promo_rule_discount_amount`, `ip`, `is_deleted`, `update_time`)
        VALUES( %s, %s, %s, 730, 27, 38004, 146, 2106, 1, 1, 1, 2, 10.00, 1530187765, 1530187765,
               'WeixinMobileWap', 0, 0, 0, 0, 10.00, 0.00, 0.00, '', 0.00, '', 0.00, 0.00, '172.20.50.73', 0,
               1530187765);'''%(2000,1+i,1+i) #2000080257

        #print(sql)


        insert_mysql(conf, sql)
        print('执行完成')
